<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.beaut.project.util.FlowUtility" %>
<%@ include file="/public/header.jsp"%>

<html>
	<head>
		<title>项目开票管理</title>
	</head>
	<script type="text/javascript">
	   var id='';
		$(function(){
				jQuery("#searchValue").keypress(function(e) { 
			    	// 回车键事件 
			     	if(e.which == 13) { 
			     		 doSearch();
			       	} 
				});
				jQuery("#dept_id").combotree({
					url:'<%=contextPath %>/springMVC/group/listDepartment',
					method:'POST',
					animate:true,
					lines:true,
					onChange:function(){
						doSearch();
					}
				});
				jQuery('#person_id').combogrid({
					title:'人员选择',
					mode:"remote",
					loadMsg:'正在加载数据，请稍后......',
					panelWidth:550,
					panelHeight:400,
					url:"<%=contextPath%>/springMVC/group/listPageUser",
					idField:"id",
					textField:"truename",
					rownumbers:true,
					fitColumns:true,
					columns: [[
						{field:'id',hidden:true},
						{field:'deptId',hidden:true},
						{field:'truename',title:'姓名',width:100},
						{field:'deptName',title:'所属部门',width:100},
						{field:'privName',title:'角色',width:100}
					]],
					toolbar:"#tb",
					pageSize:10,
					pageList:[10,50,100],  
					pagination:true,
					onChange:function(){
						doSearch();
					}
				});
			jQuery("#dd").hide();
			$("#table").datagrid({
				title:"项目开票管理",
				iconCls:'icon-edit',
				loadMsg:'正在加载数据，请稍后......',
				url:'<%=contextPath %>/springMVC/xmFinance/listPageXMInvoice?status=3',
				rownumbers:true,
				fitColumns:true,
				nowrap:false,
				idField:'id',
				frozenColumns:[[
				    {title:'主键',field:'id',hidden:true},
				]],
				columns:[[
					{title:'所属部门',field:'dept_name',width:100,align:'center'},
					{title:'项目编号',field:'xm_code',width:100,align:'center'},
					{title:'项目名称',field:'xm_name',width:200,align:'center'},
					{title:'票据抬头',field:'invoice_title',width:200,align:'center'},
					{title:'票号',field:'showInvoiceCode',width:300,align:'center',formatter:function(value,rowData,rowIndex){
						var str="";
						if(isNaN(rowData.invoice_code) || rowData.invoice_code=='' || rowData.invoice_code=='NULL'){
							str="无";
						}else {
							str=rowData.invoice_code;
						}
						str+= "&nbsp;&nbsp;<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-edit' title='票号输入' onclick=\"javascript:addCode('"+rowData.id+"','"+rowData.xm_name+"');\"/>&nbsp;&nbsp;";
	
						return str;
						
					}},
					{title:'开票人',field:'creator',width:100,align:'center'},
					{title:'开票额',field:'account_receivable',width:100,align:'center'},
					{title:'已收额',field:'has_receivable',width:100,align:'center'},
					{title:'预警时间',field:'alarm_time',width:100,align:'center'},
					{title:'摘要',field:'remark',width:100,align:'center'},
					{title:'创建时间',field:'create_time',width:100,align:'center'},
					{title:'处理状态',field:'status',width:100,align:'center',formatter:function(value,rowData,rowIndex){
						if(isNaN(rowData.invoice_code) || rowData.invoice_code=='' || rowData.invoice_code=='NULL'){
							return "未处理";
						}else {
							return "已处理";
						}
						
					}}
				]],
				pageSize:10,
				pageList : [10,50,100],  
				pagination:true,
				onLoadSuccess:function(rtJson){
					if(rtJson.rtState== '1')
					{
						$.messager.alert('提示',rtJson.rtMsrg);
					}
				}
			});
		});
		
		function addCode(invoice_id,xm_name){
		id=invoice_id;
		jQuery("#invoice_code").val('');
			jQuery('#dd').dialog({
				        title: '【'+xm_name+'】请输入票号',
				        width: 300,
				        height: 80,
				        top:110,
				        closed: false,
				        cache: false,
				        href: '',
				        modal: true
				        });
					jQuery("#dd").show();
        }
        function updateInvoice(){
        var invoice_code=jQuery("#invoice_code").val();
        param="id="+id+"&invoice_code="+invoice_code;
          $.ajax({
						type:'POST',
						url:'<%=contextPath %>/springMVC/xmFinance/updateInvoiceCode',
						dataType:"JSON",
						data:param,
						success:function(rtJson){
							if (rtJson.rtState == '0'){
									$.messager.alert("提示",rtJson.rtMsrg);
									rtCallBack();
									jQuery('#dd').dialog('close'); 
							}else{
								warningInfo(rtJson.rtMsrg);
							}
						}
					});
        
        }
		


		function rtCallBack(){
			$('#table').datagrid('reload');
		}
		 function doSearch()
			{
			  var start_time=jQuery('#start_time').datebox('getValue');  
				var end_time=jQuery('#end_time').datebox('getValue');  
				var searchValue = jQuery('#searchValue').val();
				var dept_id = jQuery("#dept_id").combotree('getValue');
				var person_id = jQuery("#person_id").combotree('getValue');
				jQuery('#table').datagrid('load', {
					start_time:start_time,
					end_time:end_time,
					searchValue:searchValue,
					dept_id:dept_id,
					person_id:person_id
				});
			}
	</script>
	<body  >
				<div id="table"  data-options="toolbar:'#tb'"></div>  
								<div id="tb" style="padding:3px;height:auto">
					<div align="right">
							开始时间：<input id="start_time" name="start_time" class="easyui-datebox" style="width:100px" />&nbsp;&nbsp;&nbsp;结束时间：<input id="end_time" name="end_time" class="easyui-datebox" style="width:100px"/>
							所属部门：<input  id="dept_id" name="dept_id" class="easyui-combotree" style="width:140px">&nbsp;&nbsp; 
							开票人：<input type="text" id="person_id" name="person_id"   style="width:100px">
							项目编号/名称：<input id="searchValue" name="searchValue" style="width:120px" title="项目编号/名称" placeholder="项目编号/名称" />&nbsp;&nbsp; 
							<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="doSearch();"></a>
			</div>
		</div>
		
		<div id="dd"  >
				<div style="text-align:center;">
					<input type="text" id="invoice_code" name="invoice_code"  data-options="required:true">
									<a href="javascript:updateInvoice()" class="easyui-linkbutton">保存</a>
				</div>

		</div>
	</body>
</html>
